/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.oea.struts.forms;


import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

/**
 *
 * @author Sony
 */
public class StudentRegisterForm extends org.apache.struts.action.ActionForm {
    
    
    private String fname,mname,lname,gender,email,password,contact,enrollmentno;
    private Long addedby,id;
    private boolean status;

    public boolean isStatus() {
        return status;
    }

    public void setStatus(boolean status) {
        this.status = status;
    }
    
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    
    public Long getAddedby() {
        return addedby;
    }

    public void setAddedby(Long addedby) {
        this.addedby = addedby;
    }
    
   
    
    
    

    public String getFname() {
        return fname;
    }

    public void setFname(String fname) {
        this.fname = fname;
    }

    public String getMname() {
        return mname;
    }

    public void setMname(String mname) {
        this.mname = mname;
    }

    public String getLname() {
        return lname;
    }

    public void setLname(String lname) {
        this.lname = lname;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

   

    public String getContact() {
        return contact;
    }

    public void setContact(String contact) {
        this.contact = contact;
    }

    public String getEnrollmentno() {
        return enrollmentno;
    }

    public void setEnrollmentno(String enrollmentno) {
        this.enrollmentno = enrollmentno;
    }

   
    

    /**
     * @return
     */
    
    /**
     *
     */
    public StudentRegisterForm() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * This is the action called from the Struts framework.
     *
     * @param mapping The ActionMapping used to select this instance.
     * @param request The HTTP Request we are processing.
     * @return
     */
    @Override
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        ActionErrors errors = new ActionErrors();
         
        Pattern enroll_regex = Pattern.compile("[0-9]{12}");
        Matcher enroll_matcher = enroll_regex.matcher(getEnrollmentno());
        
        
        Pattern contact_regex = Pattern.compile("[7-9][0-9]{9}");
        Matcher contact_matcher = contact_regex.matcher(getContact());
        
        Pattern fname_regex = Pattern.compile("[a-z|A-Z]+");
        Matcher fname_matcher = fname_regex.matcher(getFname());
        
        Pattern mname_regex = Pattern.compile("[a-z|A-Z]+");
        Matcher mname_matcher = mname_regex.matcher(getMname());
        
        Pattern lname_regex = Pattern.compile("[a-z|A-Z]+");
        Matcher lname_matcher = lname_regex.matcher(getLname());

        
        Pattern email_regex = Pattern.compile("[a-z|A-Z]+");
        Matcher email_matcher = email_regex.matcher(getEmail());
        
        if (getEnrollmentno() == null || getEnrollmentno().length() < 1) {
             
            errors.add("enrollmentno", new ActionMessage("student-register-error-enrollno-required"));
            // TODO: add 'error.name.required' key to your resources
        }
        
        if (!enroll_matcher.matches()) {
             errors.add("enrollmentno", new ActionMessage("student-register-error-enrollno-valid"));
        }
        
        if (getFname() == null || getFname().length() < 1) {
            errors.add("fname", new ActionMessage("student-register-error-fname-required"));
            // TODO: add 'error.name.required' key to your resources
        }
        if (!fname_matcher.matches()) {
             errors.add("fname", new ActionMessage("student-register-error-fname-valid"));
        }
        
        if (getMname() == null || getMname().length() < 1) {
             errors.add("mname", new ActionMessage("student-register-error-mname-required"));
            // TODO: add 'error.name.required' key to your resources
        }
        if (getLname() == null || getLname().length() < 1) {
            errors.add("lname", new ActionMessage("student-register-error-lname-required"));
            // TODO: add 'error.name.required' key to your resources
        }
        if (getGender() == null || getGender().length() < 1) {
            errors.add("gender", new ActionMessage("student-register-error-gender-required"));
            // TODO: add 'error.name.required' key to your resources
        }
        if (getEmail() == null || getEmail().length() < 1) {
            // System.out.println(" Error Avi bhai");
            errors.add("email", new ActionMessage("student-register-error-email-required"));
            // TODO: add 'error.name.required' key to your resources
        }
//        if (!email_matcher.matches()) {
//             errors.add("email", new ActionMessage("student-register-error-email-valid"));
//        }
        
        if (getPassword() == null || getPassword().length() < 1) {
            // System.out.println(" Error Avi bhai");
            errors.add("password", new ActionMessage("student-register-error-password-required"));
            // TODO: add 'error.name.required' key to your resources
        }
               if (getContact() == null || getContact().length() != 10) {
            // System.out.println(" Error Avi bhai");
            errors.add("contact", new ActionMessage("student-register-error-contact-required"));
            // TODO: add 'error.name.required' key to your resources
        }
          if (!contact_matcher.matches()) {
             errors.add("contact", new ActionMessage("student-register-error-contact-valid"));
         }
       
        return errors;
    }
}
